package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@Slf4j
@Api(tags = "订单相关接口")
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 历史订单查询
     *
     * @param
     * @return
     */
    @ApiOperation("查询历史订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> pageOrder(@RequestParam Integer page,
                                        @RequestParam Integer pageSize,
                                        @RequestParam(required = false) Integer status) {
        OrdersPageQueryDTO dto = OrdersPageQueryDTO.builder()
                .page(page)
                .pageSize(pageSize)
                .status(status)
                .build();
        return Result.success(orderService.pageOrder(dto));
    }

    /**
     * 取消订单
     *
     * @param id
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result<String> cancel(@PathVariable Long id) {
        orderService.cancel(id);
        return Result.success();
    }

    /**
     * 查询订单详细
     * @param id
     * @return
     */
    @ApiOperation("查询订单详细")
    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id){
        return Result.success(orderService.orderDetail(id));
    }

    /**
     * 统计各个状态订单的数量
     * @return
     */
    @ApiOperation("统计各个状态订单的数量")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        return Result.success(orderService.statistics());
    }

    /**
     * 接单
     * @param dto
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> confirm(@RequestBody OrdersConfirmDTO dto){
        orderService.confirm(dto);
        return Result.success();
    }

    /**
     * 拒单
     * @param dto
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO dto){
        orderService.rejection(dto);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result<String> delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result<String> complete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }
}
